<?php
/**
 * Companies Autocomplete
 *
 * @author Xavier VILAIN
 * @package \Shama\Company
 * @license
 */
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Connection;
use Shama\Company;
$terms = "%".Xview::instance()->val("term")."%";
$infos = \Fox\Dao::infos(Company::className());
$query = $infos->handle()->createQueryBuilder();
$query->select("companyid as id","name1 as label")->from($infos->tableName(),"t");
$fragment = new Fox\Dao\SqlFragment("loekz = ? AND LOWER(name1) LIKE LOWER(?) "
									,array(0,$terms),
									array(Type::INTEGER,type::STRING));
$customers = $fragment->pushIn($query)->execute()->fetchAll(\PDO::FETCH_ASSOC);

echo Fox\Utilities::jsonUTF8Encode($customers);